<template>
  <div class="layout-page">
    <el-container class="layout-container">
      <!-- 左侧菜单 -->
      <el-aside :width="isCollapse ? '65px' : '200px'">
        <div class="layout-hd">
          <!-- <div :class="isCollapse ? 'minlogo' : 'maxlogo'" class="logo"></div> -->
          <div :class="[{ logo: true }, isCollapse ? 'minlogo' : 'maxlogo']"></div>
        </div>
        <el-menu
          router
          :default-active="$route.path"
          background-color="#002033"
          text-color="#fff"
          active-text-color="#ffd04b"
          :collapse="isCollapse"
          :collapse-transition="false">
          <el-menu-item index="/">
            <i class="el-icon-s-home"></i>
            <span slot="title">头条首页</span>
          </el-menu-item>
          <el-menu-item index="/content">
            <i class="el-icon-document"></i>
            <span slot="title">内容管理</span>
          </el-menu-item>
          <el-menu-item index="/imgMaterial">
            <i class="el-icon-picture"></i>
            <span slot="title">素材管理</span>
          </el-menu-item>
          <el-menu-item index="/publish">
            <i class="el-icon-s-promotion"></i>
            <span slot="title">发布文章</span>
          </el-menu-item>
          <el-menu-item index="/comment">
            <i class="el-icon-chat-dot-round"></i>
            <span slot="title">评论管理</span>
          </el-menu-item>
          <el-menu-item index="/fans">
            <i class="el-icon-setting"></i>
            <span slot="title">粉丝管理</span>
          </el-menu-item>
          <el-menu-item index="/setting">
            <i class="el-icon-user"></i>
            <span slot="title">个人设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <!-- 头部区域 -->
        <el-header class="header">
          <div class="txt-left">
            <i @click="isCollapse = !isCollapse" :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
            <span>江苏传智播客科技教育有限公司</span>
          </div>
          <div class="right-portrait">
            <el-avatar :size="30" :src="userList.photo"></el-avatar>
            <el-dropdown>
              <span class="el-dropdown-link">
                {{ userList.name }}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>设置</el-dropdown-item>
                <el-dropdown-item>退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <!-- 主题区域 -->
        <el-main>
          <!-- 存放二级路由 -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// 导入事件总线
import eventBus from '@/components/eventBus'
import { userInfo } from '@/api/user'
export default {
  name: 'Layout',
  data () {
    return {
      // 是否水平收起菜单
      isCollapse: false,
      // 用户信息
      userList: {}
    }
  },
  mounted () {
    this.getUserInfo()
    // 接收Setting组件的出传的用户名
    eventBus.$on('inform-user', data => {
      this.userList.name = data.name
    })
    // 接收Setting组件的出传的用户头像
    eventBus.$on('inform-img', data => {
      this.userList.photo = data.photo
    })
  },
  methods: {
    // 获取个人信息
    async getUserInfo () {
      const { data: { data } } = await userInfo()
      this.userList = data
    }
  }
}
</script>

<style lang="less" scoped>
// 占满整个容器
.layout-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.el-header {
  background-color: #fff;
  color: #333;
  border-bottom: 1px solid #ccc;
}
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;

  .right-portrait {
    display: flex;
    align-items: center;
    cursor: pointer;
    .el-avatar {
      margin-right: 10px;
      // vertical-align: middle;
    }
    // .el-dropdown {

    // }
  }
}

.el-aside {
  background-color: #002033;
  color: #333;
}
/deep/.el-menu {
  border: none;
}
.layout-hd {
  background-color: #024;
  .logo {
    width: 100%;
    height: 60px;
    // background-position: center center;
  }
  .maxlogo {
    background: url('../../assets/images/logo_admin.png') no-repeat 50%;
    background-size: 140px auto;
  }
  .minlogo {
    background: url('../../assets/images/logo_admin_01.png') no-repeat 50%;
    background-size: 36px auto;
  }
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
}
</style>
